//userService
const db = require("../../config/db.config"); //引入数据库封装模块
const setParamsObj = require("../../tools/setParams"); //引入数据库封装模块

const FrontEndQuestionsService = {
    searchFrontEndQuestions: async (params) =>{
      let sql = 'select * from fontendquestions'
      sql += setParamsObj.setParams(params, ['questiontitle'])
      const data = await db.query(sql, '')
      return data
    },
    addFrontEndQuestions: async (params) =>{
      const sql = `insert into fontendquestions (questiontitle, answer, info, type) values (?, ?, ?, ?)`
      const data = await db.query(sql, [params.questiontitle, params.answer, params.info, params.type])
      return data
    },
    delFrontEndQuestions: async (params) =>{
      const sql = `delete from fontendquestions where id = ?`
      const data = await db.query(sql, params.id)
      return data
    },
    updateFrontEndQuestions: async (params) =>{
      const sql = `update fontendquestions set questiontitle = ?, answer = ?, info = ?, type = ? where id = ?`
      const data = await db.query(sql, [params.questiontitle, params.answer, params.info, params.type, params.id])
      return data
    },
    getAllType: async (params) =>{
      const sql = `select * from fontendquestionstype`
      const data = await db.query(sql, '')
      return data
    },
    
}
setInterval(() => {
  FrontEndQuestionsService.searchFrontEndQuestions({})
// }, 7 * 60 * 60 * 1000);
}, 1 * 60 * 60 * 1000);

module.exports = FrontEndQuestionsService
